<?php

require_once("inc/dbConnection.php");

class student {

	private static $instance;

	// private constructor
	private function __construct() {}
    
    
	public static function getInstance() {
    
		if(!isset(self::$instance)) {
			$object= __CLASS__;
			self::$instance = new $object;
		}

		return self::$instance;
	}
    
    
    
    // get mysql result set type as set of all accounts
    function get_available_sessions() {
    
        $db = new Dbo();

        $sql = "SELECT " .
                "`session_id`, `name`, `description`, `starttime`,`duration`, `firstname`, `lastname`, `max_student` " .
            "FROM " .
                "tutor_session LEFT JOIN accounts ON `tutor_session`.`tutor` = `accounts`.`account_id`";
        
        
        $result = $db->runQuery($sql);
        return $result;
    }
    
    
    
    // add an account to the existing db
    function enroll($student_id, $session_id) {
    
        $db = new Dbo();
        
        $sql = "INSERT INTO `session_enrollment` " .
            "(`student_id`,`session_id`) " .
            "VALUES ({$student_id},{$session_id})";
            
        $result = $db->runQuery($sql);
    }
    
    
        // add an account to the existing db
    function disenroll($student_id, $session_id) {
    
        $db = new Dbo();
        
        $sql = "DELETE FROM `session_enrollment` " .
            "WHERE student_id = {$student_id} AND session_id = {$session_id}";
        
        $result = $db->runQuery($sql);
    }
    
    function get_session_enrollment($session_id) {
        
        $db = new Dbo();
        
        $sql = "SELECT COUNT(*) FROM session_enrollment WHERE session_id = {$session_id}";
        
        $result = $db->runQuery($sql);
        return $result;
    }
}

?>